//
//  AXHomeCpsyDsfcjLsrzVC.m
//  AnXin100
//
//  Created by 天质弘耕 on 2018/11/5.
//  Copyright © 2018 tzhg. All rights reserved.
//

#import "AXHomeCpsyDsfcjLsrzVC.h"
#import "AXHomeCpsyDsfcjLsrzCell.h"
#import "AXHomeCpsyDsfcjLsrzModel.h"
#import "UIView+SDAutoLayout.h"
#import "ZXCategories.h"
#import "UITableView+SDAutoTableViewCellHeight.h"

@interface AXHomeCpsyDsfcjLsrzVC ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic , strong) UITableView *tableView;
@property (nonatomic , strong) NSMutableArray<AXHomeCpsyDsfcjLsrzModel *> *modelsArray;
@property (nonatomic, strong) NSArray<NSString *> *titleNames;
@property (nonatomic, strong) NSArray<NSString *> *contents;

@end

@implementation AXHomeCpsyDsfcjLsrzVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view.
    [self setupNavigationItems];
    
    /** 表头创建 */
    self.tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    self.tableView.backgroundColor = [UIColor whiteColor];
    //tableview上，滑动或者点击，textfiled收起键盘
    self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
    /** 去掉cell线 */
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerClass:[AXHomeCpsyDsfcjLsrzCell class] forCellReuseIdentifier:[AXHomeCpsyDsfcjLsrzCell reuseID]];
    [self.view addSubview:self.tableView];
    
    self.tableView.sd_layout
    .leftSpaceToView(self.view, 0)
    .topSpaceToView(self.view, NAVIGATION_HEIGHT)
    .widthIs(SCREEN_WIDTH)
    .heightIs(SCREEN_HEIGHT-NAVIGATION_HEIGHT);
    
    //测试数据
    self.titleNames = @[@"商品名称:",@"认证编号:",@"认证:",@"认证机构:",@"有效期:",@"产地:"];
    self.contents = @[@"石榴",@"12504698225",@"有机食品",@"专家检测机构",@"2018-01.04-2019.01。04",@"云南省昆明市盘龙区"];
    
    
}

- (void)setupNavigationItems {
    
    /** 导航条左边的按钮 */
    //返回按钮
    UIButton *kfBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [kfBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    kfBtn.frame = CGRectMake(0, 0, 30, 30);
    [kfBtn addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:kfBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    UILabel *titleLabel = [[UILabel alloc]init];
    titleLabel.textColor = [UIColor colorWithHex:0x29b566];
    titleLabel.text = @"绿色认证查询";
    self.navigationItem.titleView = titleLabel;
    
    
}

#pragma mark - Action

- (void)backAction:(UIBarButtonItem *)item {
    [self.navigationController popViewControllerAnimated:YES];
}




#pragma mark - tableViewDelegate & tableViewDatasorce
//分区头
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_HEIGHT, 200)];
    view.backgroundColor = [UIColor whiteColor];

    UILabel *inputLabel = [[UILabel alloc]init];
    inputLabel.text = @"输入名称";
    inputLabel.font = FONT_FOURTEEN;
    inputLabel.textColor = COLOR_DIV;
    [view addSubview:inputLabel];
    
    inputLabel.sd_layout
    .leftSpaceToView(view, 10)
    .topSpaceToView(view, 30)
    .widthIs(70)
    .heightIs(30);
    
    
    UITextField *inputTextField = [[UITextField alloc]init];
    inputTextField.layer.borderColor = [UIColor lightGrayColor].CGColor;
    inputTextField.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    inputTextField.layer.borderWidth = 0.5;
    inputTextField.borderStyle = UITextBorderStyleNone;
    inputTextField.font = FONT_FOURTEEN;
    inputTextField.textColor = COLOR_DIV;
    inputTextField.layer.cornerRadius = 3;
    inputTextField.layer.masksToBounds = YES;
    [inputTextField addTextIndent:5];
    [view addSubview:inputTextField];
    
    inputTextField.sd_layout
    .leftSpaceToView(inputLabel, 10)
    .widthIs(SCREEN_WIDTH-180)
    .heightRatioToView(inputLabel, 1)
    .topEqualToView(inputLabel);
    
    
    UILabel *numLabel= [[UILabel alloc]init];
    numLabel.text = @"输入编号";
    numLabel.font = FONT_FOURTEEN;
    numLabel.textColor = COLOR_DIV;
    [view addSubview:numLabel];
    
    
     numLabel.sd_layout
    .leftSpaceToView(view, 10)
    .topSpaceToView(inputLabel, 10)
    .widthIs(70)
    .heightIs(30);
    
    UITextField *numTextField = [[UITextField alloc]init];
    numTextField.font = FONT_FOURTEEN;
    numTextField .layer.borderColor = [UIColor lightGrayColor].CGColor;
    numTextField .contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    numTextField .layer.borderWidth = 0.5;
    numTextField .borderStyle = UITextBorderStyleNone;
    numTextField .textColor = COLOR_DIV;
    numTextField .layer.cornerRadius = 3;
    numTextField .layer.masksToBounds = YES;
    [numTextField  addTextIndent:5];
    [view addSubview:numTextField ];
    
     numTextField.sd_layout
     .widthIs(SCREEN_WIDTH-180)
    .leftSpaceToView(numLabel, 10)
    .heightRatioToView(numLabel, 1)
    .topEqualToView(numLabel);
    
    
    
    UIButton *queryBtn = [[UIButton alloc]init];
    queryBtn.backgroundColor = COLOR_GREEN;
    queryBtn.cornerRadius = 5;
    [queryBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [queryBtn setTitle:@"立即查询" forState:UIControlStateNormal];
    [queryBtn addTarget:self action:@selector(query:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:queryBtn];
    
    
    queryBtn.sd_layout
    .centerXEqualToView(view)
    .topSpaceToView(numLabel, 50)
    .widthIs(100)
    .heightIs(40);
    
    
    
    return view;
    
    
    
}




#pragma mark - Button action

- (void)query:(UIButton *)btn {
    
}

/** 分区的高度 */

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    
    return 200;
    
}

//几个分区
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 6;
}

/** cell的高度 */

/** cell 自适应第二步 */
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    return 44;
    
    
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    
    AXHomeCpsyDsfcjLsrzCell *cell = [tableView dequeueReusableCellWithIdentifier:[AXHomeCpsyDsfcjLsrzCell reuseID] forIndexPath:indexPath];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    cell.titleLabel.text = self.titleNames[indexPath.row];
    cell.contentLabel.text = self.contents[indexPath.row];
    
    
    
    return cell;
    
    
}







@end
